package 力扣日常刷题.木23一月.第09天309;

import 力扣日常刷题.ListNode;

/**
 * @author 帅小伙
 * @date 2022/3/9
 * @description
 */
public class Demo32反转链表 {

    public ListNode reverseList(ListNode head) {
        ListNode cur = head;
        ListNode pre = null;
        while(cur != null) {
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
        return pre;
    }


    public ListNode reverseList2(ListNode head) {
        if(head == null || head.next == null) return head;
        ListNode nHead = reverseList2(head.next);
       head.next.next = head;
        head.next = null;
        return nHead;
    }

}
